﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System;
using System.Windows;
using System.Windows.Navigation;

#endregion

namespace Majesty_of_Omega.GUI.Controls
{
    /// <summary>
    /// The Navigaton panel allows the user to navigate between Pages in a Wizard like Style.
    /// The Panel resists like a Vista Task Bar in the lower side of the page. It contains a forward
    /// and a backward button
    /// </summary>
    public partial class NavigationPanel
    {
        /// <summary>
        /// Identifies the ClickForward routed event.
        /// </summary>
        public static readonly RoutedEvent ClickForwardEvent = EventManager.RegisterRoutedEvent(
            "ClickForward", RoutingStrategy.Bubble,
            typeof (RoutedEventHandler), typeof (NavigationPanel));

        /// <summary>
        /// <see cref="Uri"/>  of the Forward Navigation
        /// </summary>
        private Uri _NavigatePageForward;

        /// <summary>
        /// Initialize Component
        /// </summary>
        public NavigationPanel()
        {
            InitializeComponent();
        }

        ///<summary>
        /// Sets the uri for the forward button
        ///</summary>
        public string NavigatePageForward
        {
            get { return _NavigatePageForward.ToString(); }
            set { _NavigatePageForward = new Uri(value, UriKind.RelativeOrAbsolute); }
        }

        /// <summary>
        /// Gets the navigation service from this form.
        /// </summary>
        /// <value>The navigation service.</value>
        private NavigationService NavigationService
        {
            get { return NavigationService.GetNavigationService(this); }
        }

        /// <summary>
        /// Handles the Click event of the BackwardButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void BackwardButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }

        /// <summary>
        /// Classic C# Event handling
        /// </summary>
        public event RoutedEventHandler ClickForward
        {
            add { AddHandler(ClickForwardEvent, value); }
            remove { RemoveHandler(ClickForwardEvent, value); }
        }

        /// <summary>
        /// Handles the click on the forward button.
        /// a) Raise a routed Event "ClickForward"
        /// b) Navigate ot the associated property
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void ForwardButton_Click(object sender, RoutedEventArgs e)
        {
            RaiseEvent(new RoutedEventArgs(ClickForwardEvent));

            if (_NavigatePageForward != null)
                NavigationService.Navigate(_NavigatePageForward);
        }
    }
}